package edu.nwpu.zya.coreops.modules.alert.controller;

import edu.nwpu.zya.coreops.common.utils.R;
import edu.nwpu.zya.coreops.common.utils.ShiroUtils;
import edu.nwpu.zya.coreops.modules.alert.service.StatisticService;
import edu.nwpu.zya.coreops.modules.alert.vo.AlertLevelCountVo;
import edu.nwpu.zya.coreops.modules.alert.vo.MetricVo;
import edu.nwpu.zya.coreops.modules.alert.vo.OccurTrendVo;
import edu.nwpu.zya.coreops.modules.alert.vo.RecoveryTrendVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("alert/statistic")
public class HistoryStatisticController {
    @Autowired
    private StatisticService statisticService;

    /**
     * 获取发生告警的历史趋势
     * @param params
     * @return
     */
    @GetMapping("/history/occur")
    public R occurTrend(@RequestParam Map<String, Object> params){
        params.put("userId", ShiroUtils.getUserId());
        List<OccurTrendVo> occurTrendVos =statisticService.getOccurTrendByParams(params);

        return R.ok().put("historyTrend", occurTrendVos);
    }
    /**
     * 获取发生告警的历史趋势
     * @param params
     * @return
     */
    @GetMapping("/history/recovery")
    public R recoveryTrend(@RequestParam Map<String, Object> params){
        params.put("userId", ShiroUtils.getUserId());
        List<RecoveryTrendVo> recoveryTrendVos =statisticService.getRecoveryTrendByParams(params);

        return R.ok().put("historyTrend", recoveryTrendVos);
    }

    @GetMapping("/history/level")
    public R historyLevel(@RequestParam Map<String,Object> params){
        params.put("userId",ShiroUtils.getUserId());
        List<AlertLevelCountVo> alertLevelCountVos =statisticService.getLevelCountByParams(params);

        return R.ok().put("historyLevel", alertLevelCountVos);
    }
    @GetMapping("/history/metric")
    public R historyMetric(@RequestParam Map<String,Object> params){
        params.put("userId",ShiroUtils.getUserId());
        List<MetricVo> metricVos=statisticService.getMetricCountByParams(params);

        return R.ok().put("historyMetric",metricVos);
    }


}
